using System;
using System.Data;

public partial class RecruitVietnam
{

    #region Add New or Update Job Posting
    public bool AddNewOrUpdateJobPosting(
    string jobID, string recuiterID,
    string jobNo, string closeDate,
    string jobTitle, string summary,
    string categoryID, string industryID,
    string certificateID, string experienceLevel, 
    string yearExperience, string workType,
    string contactEmail, string contactName, 
    string contactTel, string jobQuantity, 
    string rangeOfAge, string recruitmentType,
    bool showLogo, string minSalary, 
    string maxSalary, string currency, 
    bool negotiveSalary, bool showSalary, 
    string provinceID, string workLocation, 
    string jobSkill, string adv,  
    bool applyOnline, string applyOnlineURL,         
    string folderID, string templateID)
    { 
        bool save = false;
        errorMessage = "";
        try
        {
            SqlServerProvider sqlServerProvider
                = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText =
            "SPSavePostJob";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection = new string[32]
            {"@JobID","RecruiterID","@JobTitle", 
            "@JobNo","@RequiredNumber", "@FolderID",
            "@JobSummary","@WorkingTypeID", "@YearExperience",
            "@RangeOfAge","@RecruitmentType", "@JobSkill",
            "@ExperienceLevelID","@SalaryFrom","@SalaryTo",
            "@Currency","@ShowSalary","@SalaryNegotive",
            "@ClosedDate","@CompanyLogo","@AdvName",
            "@JobIndustryID","@JobCategoryID","@CertificateID",
            "@WorkLocation","@ProvinceID","@TemplateID",
            "@EnableApplyOnline","@OnlyApplyURL",
            "@ContactEmail","@ContactPerson","@ContactTel"};
            sqlServerProvider.ValueCollection = 
            new string[32] { jobID, recuiterID, 
                jobTitle, jobNo, jobQuantity, folderID,
                summary, workType, yearExperience,
                rangeOfAge, recruitmentType, jobSkill,
                experienceLevel, minSalary, maxSalary,
                currency, ((showSalary)?"1":"0"),
                ((negotiveSalary)?"1":"0"), closeDate,
                ((showLogo)?"1":"0"), adv, industryID,
                categoryID, certificateID,
                workLocation, provinceID,
                templateID, ((applyOnline )?"1":"0"),
                applyOnlineURL, contactEmail ,                                
                contactName, contactTel};
            sqlServerProvider.ExecuteNonQuery();
            sqlServerProvider.CloseConnection();
            save = true;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return save;
    }
    #endregion

    #region Increase Job View by Job Seeker
    public void InreaseJobView(string jobID)
    {
        errorMessage = "";
        try
        {
            SqlServerProvider sqlServerProvider
            = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText =
            "Update tblRCJobPostings set " +
            "ViewedNo = ViewedNo+1 where JobID=@JobID";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[1] { "@JobID" };
            sqlServerProvider.ValueCollection =
            new string[1] { jobID };
            sqlServerProvider.ExecuteNonQuery();
            sqlServerProvider.CloseConnection();

        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
    }
    #endregion

    #region Save Sales Package
    public int SaveSalesPackage(
      string recruiterID,
      string contactName,
      string paymentBy,
      string paymentCurrency)
    {
        errorMessage = "";
        int packageID = -1;
        try
        {
            SqlServerProvider sqlServerProvider
                        = new SqlServerProvider(connectionString);
             
            sqlServerProvider.CommandText = "SPSaveSalesPackage";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[4] { "@RecruiterID", "@ContactName", 
            "@PaymentBy", "@PaymentCurrency"};
            sqlServerProvider.ValueCollection =
            new string[4] { recruiterID, contactName, 
            paymentBy, paymentCurrency};
            sqlServerProvider.ReturnValueParameter = "@ReturnValue";
            sqlServerProvider.ExecuteNonQuery();
            sqlServerProvider.CloseConnection();
            packageID = sqlServerProvider.ReturnValue;
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;
        }
        return packageID;
    }
    #endregion

    #region Update Balance
    public bool UpdateJobViewBalance(
      string recruiterID,
      string jobs,
      string views)
    {
        errorMessage = "";
        bool save = false;
        try
        {
            SqlServerProvider sqlServerProvider
                        = new SqlServerProvider(connectionString);
             
            sqlServerProvider.CommandText = "SPPurchaseJobs";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[3] { "@RecruiterID", "@TotalJobs", 
            "@TotalViews"};
            sqlServerProvider.ValueCollection =
            new string[3] { recruiterID, jobs, 
            views};

            save = sqlServerProvider.ExecuteNonQuery()>0;
            sqlServerProvider.CloseConnection();             
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;
        }
        return save;
    }
    #endregion

    #region Deducted Job View Balance
    public bool UpdateJobViewBalance(
      string recruiterID, string type)
    {
        errorMessage = "";
        bool save = false;
        try
        {
            SqlServerProvider sqlServerProvider
                        = new SqlServerProvider(connectionString);
            
            sqlServerProvider.CommandText = "SPJobViewBalance";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[2] { "@RecruiterID", "@Type" };
            sqlServerProvider.ValueCollection =
            new string[2] { recruiterID, type};

            save = sqlServerProvider.ExecuteNonQuery() > 0;
            sqlServerProvider.CloseConnection();
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;
        }
        return save;
    }
    #endregion

    #region Check View Quota
    public int GetViewQuota(
      string recruiterID)
    {
        errorMessage = "";
        int viewQuota = 0;
        try
        {
            SqlServerProvider sqlServerProvider
                        = new SqlServerProvider(connectionString);
             
            sqlServerProvider.CommandText = "SPViewQuota";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[1] { "@RecruiterID"};
            sqlServerProvider.ValueCollection =
            new string[1] { recruiterID};

            viewQuota = Convert.ToInt32(sqlServerProvider.ExecuteScalar());
            sqlServerProvider.CloseConnection();
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;
        }
        return viewQuota;
    }
    #endregion
    
    #region Save Resume Search
    public bool SaveResumeSearch(
    string recruiter, string keyword, 
    string qualification, 
    string category, string industry,
    string province, string workingLevel,
    string workingType, string gender, 
    string available,
    string minAge , string maxAge)
    {
        bool saveSearch = false;
        errorMessage = "";
        try
        {
            SqlServerProvider sqlServerProvider
            = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText = 
            "SPSaveResumeSearch";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[12] { "@RecruiterID", "@Keyword", 
            "@Qualification", "@Category", "@Industry",
            "@Province", "@WorkingLevel", 
            "@WorkingType", "@Gender", "@Available",
            "@MinAge", "@MaxAge"};
            sqlServerProvider.ValueCollection =
            new string[12] { recruiter, keyword, 
            qualification, category, industry,
            province, workingLevel, workingType,
            gender, available, minAge, maxAge};
            saveSearch = (sqlServerProvider.ExecuteNonQuery() > 0);
            sqlServerProvider.CloseConnection();
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return saveSearch;
    }
    #endregion

    #region Save Contact
    public bool SaveContactCandidate(
    string recruiter, string jobid,
    string resumeid, string name, 
    string subject, string body)
    {
        bool save = false;
        errorMessage = "";
        try
        {
            SqlServerProvider sqlServerProvider
            = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText =
            "SPSaveContactByRecruiters";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[6] { "@RecruiterID", "@JobID", 
            "@ResumeID", "@Name", "@Subject",
            "@Body"};
            sqlServerProvider.ValueCollection =
            new string[6] { recruiter, jobid, 
            resumeid, name, subject, body};
            save  = (sqlServerProvider.ExecuteNonQuery() > 0);
            sqlServerProvider.CloseConnection();
             
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return save ;
    }
    #endregion

    #region Save Response
    public bool SaveResponse(
    string recruiter, string responseID, 
    string subject, string body, 
    string signature)
    {
        bool save = false;
        errorMessage = "";
        try
        {
            SqlServerProvider sqlServerProvider
            = new SqlServerProvider(connectionString);
            sqlServerProvider.CommandText =
            "SPSaveResponseLetter";
            sqlServerProvider.CommandType =
            CommandType.StoredProcedure;
            sqlServerProvider.ParameterCollection =
            new string[5] { "@RecruiterID", "@ResponseID",
            "@ResponseSubject", "@ResponseBody", "@ResponseSignature"};
            sqlServerProvider.ValueCollection =
            new string[5] { recruiter, responseID,
            subject, body, signature };
            save  = (sqlServerProvider.ExecuteNonQuery() > 0);
            sqlServerProvider.CloseConnection();
             
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;

        }
        return save ;
    }
    #endregion
    
}
